[#include "/pages/root/tigris-macros.ftl" /]
[@startPage pageTitle="站点功能分配"/]
	[@menuPage name="Root" /]
	<div class="rrcc">
		<div class="contnet"></div>
		<div class="right" style="display: block;">
			<div class="right01"><img src=""> 后台管理 &gt; ${pageTitle}</div>
			<div style="margin-bottom:1px;" class="contenttitle radiusbottom0">
		    	<h2 class="form" id="vertical"><span>站点功能分配</span></h2>
		    </div>
	    	[@warningMessage /]
			[@infoMessage /]
			<div style="float:left;height:350px;width:200px;border-right:2px solid #ccc;" class="stdform stdform2">
				[#assign backurl = action.getCurrentUrl() /]
				<form id="siteFunctionForm" method="post" action="[@c.url value='/root/SiteFunction_authority.action'][@c.param name="backurl" value="${backurl}" /][/@c.url]">
					<ul style="padding:8px 12px;margin-left:30px;height:300px;">
						[#list siteList as site]
							<li style="margin:4px 4px;" class="[#if siteId == site.id || (siteId == null && site_index = 0)]current[/#if]"><a href="[@c.url value="/root/SiteFunction_view.action"][@c.param name="siteId" value="${site.id}"/][/@c.url]">${site.name}</a></li>
						[/#list]
					</ul>
					<div style="width:100%; margin-top:1px;text-align:center;">
						<input type="hidden" name="siteId" value="${siteId}" />
						<input class="submit" id="sfSubmit" value="提&nbsp;&nbsp;交" type="submit" />
				        <input type="reset" value="重&nbsp;&nbsp;置" class="reset radius2" />
					</div>
				</form>
			</div>
			<div style="margin-left:210px;height:350px;overflow:auto;">
				<ul id="functionTree" class="ztree" style=""></ul>
			</div>
		</div>
	</div>
	<script>
		[#include "/pages/js/jquery.form.js"/]
		var base = (function() {
			// 事件绑定
			function _addEventListeners() {
				$('#siteFunctionForm').submit(function() {
				 	var options = { 
				 		timeout:'3000',
				 		data : {ajax:true},
				 		success: function(responseText, statusText, xhr, $form){
				 			if (statusText == "error") {
				 				alert("${action.getText('role.function.updated.error')}"); 
				 			}
				 			if (statusText == "success") {
				 				alert("${action.getText('role.function.updated.success')}"); 
				 			}
				 		}
				 	}
				 	var params = {};
				 	var zTree = $.fn.zTree.getZTreeObj("functionTree");
        			nodes = zTree.getCheckedNodes();
        			for (var n in nodes) {
        				params['siteFunctionList['+n+'].functionId'] = nodes[n].id;
        			}
        			options.data = params;
			        $(this).ajaxSubmit(options); 
			 
			        return false; 
			    }); 
			}
			// 页面渲染
			function _treeRender () {
				var zNodes =${json};
	            var setting = {
						data: {
							simpleData: {
								enable: true
							}
						}, 
						check: {
							enable: true
						}, 
						view: {
							// 渲染树
							addDiyDom: function (treeId, treeNode) {
								// 根节点以外的父节点
								//if (treeNode.pId != null) {
								//	$('#' + treeNode.tId).append("<a href='javascript:void(0);' onClick=\"return base.rmDir('" + treeNode.id + "')\">[删除]</a>");
								//}
							}
						},
						callback: {
							onClick: function(event, treeId, treeNode, clickFlag){
								//var isParent = treeNode.isParent;
								//var id = treeNode.id;
								//$.get(base.config.url, {'id':id, 'ajax':true, 'piece':true}, function(data){
				                //	$('#categoryTableList').html(data);
				                //	_addEventListeners();
				                //});
							}
						}
					};
				$.fn.zTree.init($("#functionTree"), setting, zNodes);
			}
			return {
                config: {
                	url : null,
                    theme: null
                },
                init: function () {
                	_addEventListeners();
                	_treeRender();
                }
			}
		}());
		
		$(function(){
			base.init();
		})
	</script>
[@endPage/]
